home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / doom / quake1.zip / QSLFD.ZIP / WEAPONS.QC < prev   
Text File  |  1996-08-29  |  27KB  |  1,261 lines

  1. /*
  2. */
  3. void (entity targ, entity inflictor, entity attacker, float damage) T_Damage;
  4. void () player_run;
  5. void(entity bomb, entity attacker, float rad, entity ignore) T_RadiusDamage;
  6. void(vector org, vector vel, float damage) SpawnBlood;
  7. void() SuperDamageSound;
  8.  
  9. // called by worldspawn
  10. void() W_Precache =
  11. {
  12.     precache_sound ("weapons/r_exp3.wav");    // new rocket explosion
  13.     precache_sound ("weapons/rocket1i.wav");    // spike gun
  14.     precache_sound ("weapons/sgun1.wav");
  15.     precache_sound ("weapons/guncock.wav");    // player shotgun
  16.     precache_sound ("weapons/ric1.wav");    // ricochet (used in c code)
  17.     precache_sound ("weapons/ric2.wav");    // ricochet (used in c code)
  18.     precache_sound ("weapons/ric3.wav");    // ricochet (used in c code)
  19.     precache_sound ("weapons/spike2.wav");    // super spikes
  20.     precache_sound ("weapons/tink1.wav");    // spikes tink (used in c code)
  21.     precache_sound ("weapons/grenade.wav");    // grenade launcher
  22.     precache_sound ("weapons/bounce.wav");        // grenade bounce
  23.     precache_sound ("weapons/shotgn2.wav");    // super shotgun
  24. };
  25.  
  26. float() crandom =
  27. {
  28.     return 2*(random() - 0.5);
  29. };
  30.  
  31. /*
  32. ================
  33. W_FireAxe
  34. ================
  35. */
  36. void() W_FireAxe =
  37. {
  38.     local    vector    source;
  39.     local    vector    org;
  40.  
  41.     source = self.origin + '0 0 16';
  42.     traceline (source, source + v_forward*64, FALSE, self);
  43.     if (trace_fraction == 1.0)
  44.         return;
  45.     
  46.     org = trace_endpos - v_forward*4;
  47.  
  48.     if (trace_ent.takedamage)
  49.     {
  50.         trace_ent.axhitme = 1;
  51.         SpawnBlood (org, '0 0 0', 20);
  52.         T_Damage (trace_ent, self, self, 20);
  53.     }
  54.     else
  55.     {    // hit wall
  56.         sound (self, CHAN_WEAPON, "player/axhit2.wav", 1, ATTN_NORM);
  57.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  58.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  59.         WriteCoord (MSG_BROADCAST, org_x);
  60.         WriteCoord (MSG_BROADCAST, org_y);
  61.         WriteCoord (MSG_BROADCAST, org_z);
  62.     }
  63. };
  64.  
  65.  
  66. //============================================================================
  67.  
  68.  
  69. vector() wall_velocity =
  70. {
  71.     local vector    vel;
  72.     
  73.     vel = normalize (self.velocity);
  74.     vel = normalize(vel + v_up*(random()- 0.5) + v_right*(random()- 0.5));
  75.     vel = vel + 2*trace_plane_normal;
  76.     vel = vel * 200;
  77.     
  78.     return vel;
  79. };
  80.  
  81.  
  82. /*
  83. ================
  84. SpawnMeatSpray
  85. ================
  86. */
  87. void(vector org, vector vel) SpawnMeatSpray =
  88. {
  89.     local    entity missile, mpuff;
  90.     local    vector    org;
  91.  
  92.     missile = spawn ();
  93.     missile.owner = self;
  94.     missile.movetype = MOVETYPE_BOUNCE;
  95.     missile.solid = SOLID_NOT;
  96.  
  97.     makevectors (self.angles);
  98.  
  99.     missile.velocity = vel;
  100.     missile.velocity_z = missile.velocity_z + 250 + 50*random();
  101.  
  102.     missile.avelocity = '3000 1000 2000';
  103.     
  104. // set missile duration
  105.     missile.nextthink = time + 1;
  106.     missile.think = SUB_Remove;
  107.  
  108.     setmodel (missile, "progs/zom_gib.mdl");
  109.     setsize (missile, '0 0 0', '0 0 0');        
  110.     setorigin (missile, org);
  111. };
  112.  
  113. /*
  114. ================
  115. SpawnBlood
  116. ================
  117. */
  118. void(vector org, vector vel, float damage) SpawnBlood =
  119. {
  120.     particle (org, vel*0.1, 73, damage*2);
  121. };
  122.  
  123. /*
  124. ================
  125. spawn_touchblood
  126. ================
  127. */
  128. void(float damage) spawn_touchblood =
  129. {
  130.     local vector    vel;
  131.  
  132.     vel = wall_velocity () * 0.2;
  133.     SpawnBlood (self.origin + vel*0.01, vel, damage);
  134. };
  135.  
  136.  
  137. /*
  138. ================
  139. SpawnChunk
  140. ================
  141. */
  142. void(vector org, vector vel) SpawnChunk =
  143. {
  144.     particle (org, vel*0.02, 0, 10);
  145. };
  146.  
  147. /*
  148. ==============================================================================
  149.  
  150. MULTI-DAMAGE
  151.  
  152. Collects multiple small damages into a single damage
  153.  
  154. ==============================================================================
  155. */
  156.  
  157. entity    multi_ent;
  158. float    multi_damage;
  159.  
  160. void() ClearMultiDamage =
  161. {
  162.     multi_ent = world;
  163.     multi_damage = 0;
  164. };
  165.  
  166. void() ApplyMultiDamage =
  167. {
  168.     if (!multi_ent)
  169.         return;
  170.     T_Damage (multi_ent, self, self, multi_damage);
  171. };
  172.  
  173. void(entity hit, float damage) AddMultiDamage =
  174. {
  175.     if (!hit)
  176.         return;
  177.     
  178.     if (hit != multi_ent)
  179.     {
  180.         ApplyMultiDamage ();
  181.         multi_damage = damage;
  182.         multi_ent = hit;
  183.     }
  184.     else
  185.         multi_damage = multi_damage + damage;
  186. };
  187.  
  188. /*
  189. ==============================================================================
  190.  
  191. BULLETS
  192.  
  193. ==============================================================================
  194. */
  195.  
  196. /*
  197. ================
  198. TraceAttack
  199. ================
  200. */
  201. void(float damage, vector dir) TraceAttack =
  202. {
  203.     local    vector    vel, org;
  204.     
  205.     vel = normalize(dir + v_up*crandom() + v_right*crandom());
  206.     vel = vel + 2*trace_plane_normal;
  207.     vel = vel * 200;
  208.  
  209.     org = trace_endpos - dir*4;
  210.  
  211.     if (trace_ent.takedamage)
  212.     {
  213.         SpawnBlood (org, vel*0.2, damage);
  214.         AddMultiDamage (trace_ent, damage);
  215.     }
  216.     else
  217.     {
  218.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  219.         WriteByte (MSG_BROADCAST, TE_GUNSHOT);
  220.         WriteCoord (MSG_BROADCAST, org_x);
  221.         WriteCoord (MSG_BROADCAST, org_y);
  222.         WriteCoord (MSG_BROADCAST, org_z);
  223.     }
  224. };
  225.  
  226. /*
  227. ================
  228. FireBullets
  229.  
  230. Used by shotgun, super shotgun, and enemy soldier firing
  231. Go to the trouble of combining multiple pellets into a single damage call.
  232. ================
  233. */
  234. void(float shotcount, vector dir, vector spread) FireBullets =
  235. {
  236.     local    vector direction;
  237.     local    vector    src;
  238.     
  239.     makevectors(self.v_angle);
  240.  
  241.     src = self.origin + v_forward*10;
  242.     src_z = self.absmin_z + self.size_z * 0.7;
  243.  
  244.     ClearMultiDamage ();
  245.     while (shotcount > 0)
  246.     {
  247.         direction = dir + crandom()*spread_x*v_right + crandom()*spread_y*v_up;
  248.  
  249.         traceline (src, src + direction*2048, FALSE, self);
  250.         if (trace_fraction != 1.0)
  251.             TraceAttack (4, direction);
  252.  
  253.         shotcount = shotcount - 1;
  254.     }
  255.     ApplyMultiDamage ();
  256. };
  257.  
  258. /*
  259. ================
  260. W_FireShotgun
  261. ================
  262. */
  263. void() W_FireShotgun =
  264. {
  265.     local vector dir;
  266.  
  267.     sound (self, CHAN_WEAPON, "weapons/guncock.wav", 1, ATTN_NORM);    
  268.  
  269.     self.punchangle_x = -2;
  270.     
  271.     self.currentammo = self.ammo_shells = self.ammo_shells - 1;
  272.     dir = aim (self, 100000);
  273.     FireBullets (6, dir, '0.04 0.04 0');
  274. };
  275.  
  276.  
  277. /*
  278. ================
  279. W_FireSuperShotgun
  280. ================
  281. */
  282. void() W_FireSuperShotgun =
  283. {
  284.     local vector dir;
  285.  
  286.     if (self.currentammo == 1)
  287.     {
  288.         W_FireShotgun ();
  289.         return;
  290.     }
  291.         
  292.     sound (self ,CHAN_WEAPON, "weapons/shotgn2.wav", 1, ATTN_NORM);    
  293.  
  294.     self.punchangle_x = -4;
  295.     
  296.     self.currentammo = self.ammo_shells = self.ammo_shells - 2;
  297.     dir = aim (self, 100000);
  298.     FireBullets (14, dir, '0.14 0.08 0');
  299. };
  300.  
  301.  
  302. /*
  303. ==============================================================================
  304.  
  305. ROCKETS
  306.  
  307. ==============================================================================
  308. */
  309.  
  310. void()    s_explode1    =    [0,        s_explode2] {};
  311. void()    s_explode2    =    [1,        s_explode3] {};
  312. void()    s_explode3    =    [2,        s_explode4] {};
  313. void()    s_explode4    =    [3,        s_explode5] {};
  314. void()    s_explode5    =    [4,        s_explode6] {};
  315. void()    s_explode6    =    [5,        SUB_Remove] {};
  316.  
  317. void() BecomeExplosion =
  318. {
  319.     self.movetype = MOVETYPE_NONE;
  320.     self.velocity = '0 0 0';
  321.     self.touch = SUB_Null;
  322.     setmodel (self, "progs/s_explod.spr");
  323.     self.solid = SOLID_NOT;
  324.     s_explode1 ();
  325. };
  326.  
  327. void() T_MissileTouch =
  328. {
  329.     local float    damg;
  330.  
  331.     if (other == self.owner)
  332.         return;        // don't explode on owner
  333.  
  334.     if (pointcontents(self.origin) == CONTENT_SKY)
  335.     {
  336.         remove(self);
  337.         return;
  338.     }
  339.  
  340.     damg = 100 + random()*20;
  341.     
  342.     if (other.health)
  343.     {
  344.         if (other.classname == "monster_shambler")
  345.             damg = damg * 0.5;    // mostly immune
  346.         T_Damage (other, self, self.owner, damg );
  347.     }
  348.  
  349.     // don't do radius damage to the other, because all the damage
  350.     // was done in the impact
  351.     T_RadiusDamage (self, self.owner, 120, other);
  352.  
  353. //    sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  354.     self.origin = self.origin - 8*normalize(self.velocity);
  355.  
  356.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  357.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  358.     WriteCoord (MSG_BROADCAST, self.origin_x);
  359.     WriteCoord (MSG_BROADCAST, self.origin_y);
  360.     WriteCoord (MSG_BROADCAST, self.origin_z);
  361.  
  362.     BecomeExplosion ();
  363. };
  364.  
  365.  
  366.  
  367. /*
  368. ================
  369. W_FireRocket
  370. ================
  371. */
  372. void() W_FireRocket =
  373. {
  374.     local    entity missile, mpuff;
  375.     
  376.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  377.     
  378.     sound (self, CHAN_WEAPON, "weapons/sgun1.wav", 1, ATTN_NORM);
  379.  
  380.     self.punchangle_x = -2;
  381.  
  382.     missile = spawn ();
  383.     missile.owner = self;
  384.     missile.movetype = MOVETYPE_FLYMISSILE;
  385.     missile.solid = SOLID_BBOX;
  386.         
  387. // set missile speed    
  388.  
  389.     makevectors (self.v_angle);
  390.     missile.velocity = aim(self, 1000);
  391.     missile.velocity = missile.velocity * 1000;
  392.     missile.angles = vectoangles(missile.velocity);
  393.     
  394.     missile.touch = T_MissileTouch;
  395.     
  396. // set missile duration
  397.     missile.nextthink = time + 5;
  398.     missile.think = SUB_Remove;
  399.  
  400.     setmodel (missile, "progs/missile.mdl");
  401.     setsize (missile, '0 0 0', '0 0 0');        
  402.     setorigin (missile, self.origin + v_forward*8 + '0 0 16');
  403. };
  404.  
  405. /*
  406. ===============================================================================
  407.  
  408. LIGHTNING
  409.  
  410. ===============================================================================
  411. */
  412.  
  413. /*
  414. =================
  415. LightningDamage
  416. =================
  417. */
  418. void(vector p1, vector p2, entity from, float damage) LightningDamage =
  419. {
  420.     local entity        e1, e2;
  421.     local vector        f;
  422.     
  423.     f = p2 - p1;
  424.     normalize (f);
  425.     f_x = 0 - f_y;
  426.     f_y = f_x;
  427.     f_z = 0;
  428.     f = f*16;
  429.  
  430.     e1 = e2 = world;
  431.  
  432.     traceline (p1, p2, FALSE, self);
  433.     if (trace_ent.takedamage)
  434.     {
  435.         particle (trace_endpos, '0 0 100', 225, damage*4);
  436.         T_Damage (trace_ent, from, from, damage);
  437.         if (self.classname == "player")
  438.         {
  439.             if (other.classname == "player")
  440.                 trace_ent.velocity_z = trace_ent.velocity_z + 400;
  441.         }
  442.     }
  443.     e1 = trace_ent;
  444.  
  445.     traceline (p1 + f, p2 + f, FALSE, self);
  446.     if (trace_ent != e1 && trace_ent.takedamage)
  447.     {
  448.         particle (trace_endpos, '0 0 100', 225, damage*4);
  449.         T_Damage (trace_ent, from, from, damage);
  450.     }
  451.     e2 = trace_ent;
  452.  
  453.     traceline (p1 - f, p2 - f, FALSE, self);
  454.     if (trace_ent != e1 && trace_ent != e2 && trace_ent.takedamage)
  455.     {
  456.         particle (trace_endpos, '0 0 100', 225, damage*4);
  457.         T_Damage (trace_ent, from, from, damage);
  458.     }
  459. };
  460.  
  461.  
  462. void() W_FireLightning =
  463. {
  464.     local    vector        org;
  465.  
  466.     if (self.ammo_cells < 1)
  467.     {
  468.         self.weapon = W_BestWeapon ();
  469.         W_SetCurrentAmmo ();
  470.         return;
  471.     }
  472.  
  473. // explode if under water
  474.     if (self.waterlevel > 1)
  475.     {
  476.         T_RadiusDamage (self, self, 35*self.ammo_cells, world);
  477.         self.ammo_cells = 0;
  478.         W_SetCurrentAmmo ();
  479.         return;
  480.     }
  481.  
  482.     if (self.t_width < time)
  483.     {
  484.         sound (self, CHAN_WEAPON, "weapons/lhit.wav", 1, ATTN_NORM);
  485.         self.t_width = time + 0.6;
  486.     }
  487.     self.punchangle_x = -2;
  488.  
  489.     self.currentammo = self.ammo_cells = self.ammo_cells - 1;
  490.  
  491.     org = self.origin + '0 0 16';
  492.     
  493.     traceline (org, org + v_forward*600, TRUE, self);
  494.  
  495.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  496.     WriteByte (MSG_BROADCAST, TE_LIGHTNING2);
  497.     WriteEntity (MSG_BROADCAST, self);
  498.     WriteCoord (MSG_BROADCAST, org_x);
  499.     WriteCoord (MSG_BROADCAST, org_y);
  500.     WriteCoord (MSG_BROADCAST, org_z);
  501.     WriteCoord (MSG_BROADCAST, trace_endpos_x);
  502.     WriteCoord (MSG_BROADCAST, trace_endpos_y);
  503.     WriteCoord (MSG_BROADCAST, trace_endpos_z);
  504.  
  505.     LightningDamage (self.origin, trace_endpos + v_forward*4, self, 30);
  506. };
  507.  
  508.  
  509. //=============================================================================
  510.  
  511.  
  512. void() GrenadeExplode =
  513. {
  514.     T_RadiusDamage (self, self.owner, 120, world);
  515.  
  516.     WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  517.     WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  518.     WriteCoord (MSG_BROADCAST, self.origin_x);
  519.     WriteCoord (MSG_BROADCAST, self.origin_y);
  520.     WriteCoord (MSG_BROADCAST, self.origin_z);
  521.  
  522.     BecomeExplosion ();
  523. };
  524.  
  525. void() GrenadeTouch =
  526. {
  527.     if (other == self.owner)
  528.         return;        // don't explode on owner
  529.     if (other.takedamage == DAMAGE_AIM)
  530.     {
  531.         GrenadeExplode();
  532.         return;
  533.     }
  534.     sound (self, CHAN_WEAPON, "weapons/bounce.wav", 1, ATTN_NORM);    // bounce sound
  535.     if (self.velocity == '0 0 0')
  536.         self.avelocity = '0 0 0';
  537. };
  538.  
  539. /*
  540. ================
  541. W_FireGrenade
  542. ================
  543. */
  544. void() W_FireGrenade =
  545. {
  546.     local    entity missile, mpuff;
  547.     
  548.     self.currentammo = self.ammo_rockets = self.ammo_rockets - 1;
  549.     
  550.     sound (self, CHAN_WEAPON, "weapons/grenade.wav", 1, ATTN_NORM);
  551.  
  552.     self.punchangle_x = -2;
  553.  
  554.     missile = spawn ();
  555.     missile.owner = self;
  556.     missile.movetype = MOVETYPE_BOUNCE;
  557.     missile.solid = SOLID_BBOX;
  558.     missile.classname = "grenade";
  559.         
  560. // set missile speed    
  561.  
  562.     makevectors (self.v_angle);
  563.  
  564.     if (self.v_angle_x)
  565.         missile.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  566.     else
  567.     {
  568.         missile.velocity = aim(self, 10000);
  569.         missile.velocity = missile.velocity * 600;
  570.         missile.velocity_z = 200;
  571.     }
  572.  
  573.     missile.avelocity = '300 300 300';
  574.  
  575.     missile.angles = vectoangles(missile.velocity);
  576.     
  577.     missile.touch = GrenadeTouch;
  578.     
  579. // set missile duration
  580.     missile.nextthink = time + 2.5;
  581.     missile.think = GrenadeExplode;
  582.  
  583.     setmodel (missile, "progs/grenade.mdl");
  584.     setsize (missile, '0 0 0', '0 0 0');        
  585.     setorigin (missile, self.origin);
  586. };
  587.  
  588.  
  589. //=============================================================================
  590.  
  591. void() spike_touch;
  592. void() superspike_touch;
  593.  
  594.  
  595. /*
  596. ===============
  597. launch_spike
  598.  
  599. Used for both the player and the ogre
  600. ===============
  601. */
  602. void(vector org, vector dir) launch_spike =
  603. {
  604.     newmis = spawn ();
  605.     newmis.owner = self;
  606.     newmis.movetype = MOVETYPE_FLYMISSILE;
  607.     newmis.solid = SOLID_BBOX;
  608.  
  609.     newmis.angles = vectoangles(dir);
  610.     
  611.     newmis.touch = spike_touch;
  612.     newmis.classname = "spike";
  613.     newmis.think = SUB_Remove;
  614.     newmis.nextthink = time + 6;
  615.     setmodel (newmis, "progs/spike.mdl");
  616.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  617.     setorigin (newmis, org);
  618.  
  619.     newmis.velocity = dir * 1000;
  620. };
  621.  
  622. void() W_FireSuperSpikes =
  623. {
  624.     local vector    dir;
  625.     local entity    old;
  626.     
  627.     sound (self, CHAN_WEAPON, "weapons/spike2.wav", 1, ATTN_NORM);
  628.     self.attack_finished = time + 0.2;
  629.     self.currentammo = self.ammo_nails = self.ammo_nails - 2;
  630.     dir = aim (self, 1000);
  631.     launch_spike (self.origin + '0 0 16', dir);
  632.     newmis.touch = superspike_touch;
  633.     setmodel (newmis, "progs/s_spike.mdl");
  634.     setsize (newmis, VEC_ORIGIN, VEC_ORIGIN);        
  635.     self.punchangle_x = -2;
  636. };
  637.  
  638. void(float ox) W_FireSpikes =
  639. {
  640.     local vector    dir;
  641.     local entity    old;
  642.     
  643.     makevectors (self.v_angle);
  644.     
  645.     if (self.ammo_nails >= 2 && self.weapon == IT_SUPER_NAILGUN)
  646.     {
  647.         W_FireSuperSpikes ();
  648.         return;
  649.     }
  650.  
  651.     if (self.ammo_nails < 1)
  652.     {
  653.         self.weapon = W_BestWeapon ();
  654.         W_SetCurrentAmmo ();
  655.         return;
  656.     }
  657.  
  658.     sound (self, CHAN_WEAPON, "weapons/rocket1i.wav", 1, ATTN_NORM);
  659.     self.attack_finished = time + 0.2;
  660.     self.currentammo = self.ammo_nails = self.ammo_nails - 1;
  661.     dir = aim (self, 1000);
  662.     launch_spike (self.origin + '0 0 16' + v_right*ox, dir);
  663.  
  664.     self.punchangle_x = -2;
  665. };
  666.  
  667.  
  668.  
  669. .float hit_z;
  670. void() spike_touch =
  671. {
  672. local float rand;
  673.     if (other == self.owner)
  674.         return;
  675.  
  676.     if (other.solid == SOLID_TRIGGER)
  677.         return;    // trigger field, do nothing
  678.  
  679.     if (pointcontents(self.origin) == CONTENT_SKY)
  680.     {
  681.         remove(self);
  682.         return;
  683.     }
  684.     
  685. // hit something that bleeds
  686.     if (other.takedamage)
  687.     {
  688.         spawn_touchblood (9);
  689.         T_Damage (other, self, self.owner, 9);
  690.     }
  691.     else
  692.     {
  693.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  694.         
  695.         if (self.classname == "wizspike")
  696.             WriteByte (MSG_BROADCAST, TE_WIZSPIKE);
  697.         else if (self.classname == "knightspike")
  698.             WriteByte (MSG_BROADCAST, TE_KNIGHTSPIKE);
  699.         else
  700.             WriteByte (MSG_BROADCAST, TE_SPIKE);
  701.         WriteCoord (MSG_BROADCAST, self.origin_x);
  702.         WriteCoord (MSG_BROADCAST, self.origin_y);
  703.         WriteCoord (MSG_BROADCAST, self.origin_z);
  704.     }
  705.  
  706.     remove(self);
  707.  
  708. };
  709.  
  710. void() superspike_touch =
  711. {
  712. local float rand;
  713.     if (other == self.owner)
  714.         return;
  715.  
  716.     if (other.solid == SOLID_TRIGGER)
  717.         return;    // trigger field, do nothing
  718.  
  719.     if (pointcontents(self.origin) == CONTENT_SKY)
  720.     {
  721.         remove(self);
  722.         return;
  723.     }
  724.     
  725. // hit something that bleeds
  726.     if (other.takedamage)
  727.     {
  728.         spawn_touchblood (18);
  729.         T_Damage (other, self, self.owner, 18);
  730.     }
  731.     else
  732.     {
  733.         WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  734.         WriteByte (MSG_BROADCAST, TE_SUPERSPIKE);
  735.         WriteCoord (MSG_BROADCAST, self.origin_x);
  736.         WriteCoord (MSG_BROADCAST, self.origin_y);
  737.         WriteCoord (MSG_BROADCAST, self.origin_z);
  738.     }
  739.  
  740.     remove(self);
  741.  
  742. };
  743.  
  744.  
  745. /*
  746. ===============================================================================
  747.  
  748. PLAYER WEAPON USE
  749.  
  750. ===============================================================================
  751. */
  752.  
  753. void() W_SetCurrentAmmo =
  754. {
  755.     player_run ();        // get out of any weapon firing states
  756.  
  757.     self.items = self.items - ( self.items & (IT_SHELLS | IT_NAILS | IT_ROCKETS | IT_CELLS) );
  758.     
  759.     if (self.weapon == IT_AXE)
  760.     {
  761.         self.currentammo = 0;
  762.         self.weaponmodel = "progs/v_axe.mdl";
  763.         self.weaponframe = 0;
  764.     }
  765.     else if (self.weapon == IT_SHOTGUN)
  766.     {
  767.         self.currentammo = self.ammo_shells;
  768.         self.weaponmodel = "progs/v_shot.mdl";
  769.         self.weaponframe = 0;
  770.         self.items = self.items | IT_SHELLS;
  771.     }
  772.     else if (self.weapon == IT_SUPER_SHOTGUN)
  773.     {
  774.         self.currentammo = self.ammo_shells;
  775.         self.weaponmodel = "progs/v_shot2.mdl";
  776.         self.weaponframe = 0;
  777.         self.items = self.items | IT_SHELLS;
  778.     }
  779.     else if (self.weapon == IT_NAILGUN)
  780.     {
  781.         self.currentammo = self.ammo_nails;
  782.         self.weaponmodel = "progs/v_nail.mdl";
  783.         self.weaponframe = 0;
  784.         self.items = self.items | IT_NAILS;
  785.     }
  786.     else if (self.weapon == IT_SUPER_NAILGUN)
  787.     {
  788.         self.currentammo = self.ammo_nails;
  789.         self.weaponmodel = "progs/v_nail2.mdl";
  790.         self.weaponframe = 0;
  791.         self.items = self.items | IT_NAILS;
  792.     }
  793.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  794.     {
  795.         self.currentammo = self.ammo_rockets;
  796.         self.weaponmodel = "progs/v_rock.mdl";
  797.         self.weaponframe = 0;
  798.         self.items = self.items | IT_ROCKETS;
  799.     }
  800.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  801.     {
  802.         self.currentammo = self.ammo_rockets;
  803.         self.weaponmodel = "progs/v_rock2.mdl";
  804.         self.weaponframe = 0;
  805.         self.items = self.items | IT_ROCKETS;
  806.     }
  807.     else if (self.weapon == IT_LIGHTNING)
  808.     {
  809.         self.currentammo = self.ammo_cells;
  810.         self.weaponmodel = "progs/v_light.mdl";
  811.         self.weaponframe = 0;
  812.         self.items = self.items | IT_CELLS;
  813.     }
  814.     else
  815.     {
  816.         self.currentammo = 0;
  817.         self.weaponmodel = "";
  818.         self.weaponframe = 0;
  819.     }
  820. };
  821.  
  822. float() W_BestWeapon =
  823. {
  824.     local    float    it;
  825.     
  826.     it = self.items;
  827.  
  828.     if(self.ammo_cells >= 1 && (it & IT_LIGHTNING) )
  829.         return IT_LIGHTNING;
  830.     else if(self.ammo_nails >= 2 && (it & IT_SUPER_NAILGUN) )
  831.         return IT_SUPER_NAILGUN;
  832.     else if(self.ammo_shells >= 2 && (it & IT_SUPER_SHOTGUN) )
  833.         return IT_SUPER_SHOTGUN;
  834.     else if(self.ammo_nails >= 1 && (it & IT_NAILGUN) )
  835.         return IT_NAILGUN;
  836.     else if(self.ammo_shells >= 1 && (it & IT_SHOTGUN) )
  837.         return IT_SHOTGUN;
  838.         
  839. /*
  840.     if(self.ammo_rockets >= 1 && (it & IT_ROCKET_LAUNCHER) )
  841.         return IT_ROCKET_LAUNCHER;
  842.     else if(self.ammo_rockets >= 1 && (it & IT_GRENADE_LAUNCHER) )
  843.         return IT_GRENADE_LAUNCHER;
  844.  
  845. */
  846.  
  847.     return IT_AXE;
  848. };
  849.  
  850. float() W_CheckNoAmmo =
  851. {
  852.     if (self.currentammo > 0)
  853.         return TRUE;
  854.  
  855.     if (self.weapon == IT_AXE)
  856.         return TRUE;
  857.     
  858.     self.weapon = W_BestWeapon ();
  859.  
  860.     W_SetCurrentAmmo ();
  861.     
  862. // drop the weapon down
  863.     return FALSE;
  864. };
  865.  
  866. /*
  867. ============
  868. W_Attack
  869.  
  870. An attack impulse can be triggered now
  871. ============
  872. */
  873. void()    player_axe1;
  874. void()    player_axeb1;
  875. void()    player_axec1;
  876. void()    player_axed1;
  877. void()    player_shot1;
  878. void()    player_nail1;
  879. void()    player_light1;
  880. void()    player_rocket1;
  881.  
  882. void() W_Attack =
  883. {
  884.     local    float    r;
  885.  
  886.     if (!W_CheckNoAmmo ())
  887.         return;
  888.  
  889.     makevectors    (self.v_angle);            // calculate forward angle for velocity
  890.     self.show_hostile = time + 1;    // wake monsters up
  891.  
  892.     if (self.weapon == IT_AXE)
  893.     {
  894.         sound (self, CHAN_WEAPON, "weapons/ax1.wav", 1, ATTN_NORM);
  895.         r = random();
  896.         if (r < 0.25)
  897.             player_axe1 ();
  898.         else if (r<0.5)
  899.             player_axeb1 ();
  900.         else if (r<0.75)
  901.             player_axec1 ();
  902.         else
  903.             player_axed1 ();
  904.         self.attack_finished = time + 0.5;
  905.     }
  906.     else if (self.weapon == IT_SHOTGUN)
  907.     {
  908.         player_shot1 ();
  909.         W_FireShotgun ();
  910.         self.attack_finished = time + 0.5;
  911.     }
  912.     else if (self.weapon == IT_SUPER_SHOTGUN)
  913.     {
  914.         player_shot1 ();
  915.         W_FireSuperShotgun ();
  916.         self.attack_finished = time + 0.7;
  917.     }
  918.     else if (self.weapon == IT_NAILGUN)
  919.     {
  920.         player_nail1 ();
  921.     }
  922.     else if (self.weapon == IT_SUPER_NAILGUN)
  923.     {
  924.         player_nail1 ();
  925.     }
  926.     else if (self.weapon == IT_GRENADE_LAUNCHER)
  927.     {
  928.         player_rocket1();
  929.         W_FireGrenade();
  930.         self.attack_finished = time + 0.6;
  931.     }
  932.     else if (self.weapon == IT_ROCKET_LAUNCHER)
  933.     {
  934.         player_rocket1();
  935.         W_FireRocket();
  936.         self.attack_finished = time + 0.8;
  937.     }
  938.     else if (self.weapon == IT_LIGHTNING)
  939.     {
  940.         player_light1();
  941.         self.attack_finished = time + 0.1;
  942.         sound (self, CHAN_AUTO, "weapons/lstart.wav", 1, ATTN_NORM);
  943.     }
  944. };
  945.  
  946. /*
  947. ============
  948. W_ChangeWeapon
  949.  
  950. ============
  951. */
  952. void() W_ChangeWeapon =
  953. {
  954.     local    float    it, am, fl;
  955.     
  956.     it = self.items;
  957.     am = 0;
  958.     
  959.     if (self.impulse == 1)
  960.     {
  961.         fl = IT_AXE;
  962.     }
  963.     else if (self.impulse == 2)
  964.     {
  965.         fl = IT_SHOTGUN;
  966.         if (self.ammo_shells < 1)
  967.             am = 1;
  968.     }
  969.     else if (self.impulse == 3)
  970.     {
  971.         fl = IT_SUPER_SHOTGUN;
  972.         if (self.ammo_shells < 2)
  973.             am = 1;
  974.     }        
  975.     else if (self.impulse == 4)
  976.     {
  977.         fl = IT_NAILGUN;
  978.         if (self.ammo_nails < 1)
  979.             am = 1;
  980.     }
  981.     else if (self.impulse == 5)
  982.     {
  983.         fl = IT_SUPER_NAILGUN;
  984.         if (self.ammo_nails < 2)
  985.             am = 1;
  986.     }
  987.     else if (self.impulse == 6)
  988.     {
  989.         fl = IT_GRENADE_LAUNCHER;
  990.         if (self.ammo_rockets < 1)
  991.             am = 1;
  992.     }
  993.     else if (self.impulse == 7)
  994.     {
  995.         fl = IT_ROCKET_LAUNCHER;
  996.         if (self.ammo_rockets < 1)
  997.             am = 1;
  998.     }
  999.     else if (self.impulse == 8)
  1000.     {
  1001.         fl = IT_LIGHTNING;
  1002.         if (self.ammo_cells < 1)
  1003.             am = 1;
  1004.     }
  1005.  
  1006.     self.impulse = 0;
  1007.     
  1008.     if (!(self.items & fl))
  1009.     {    // don't have the weapon or the ammo
  1010.         sprint (self, "no weapon.\n");
  1011.         return;
  1012.     }
  1013.     
  1014.     if (am)
  1015.     {    // don't have the ammo
  1016.         sprint (self, "not enough ammo.\n");
  1017.         return;
  1018.     }
  1019.  
  1020. //
  1021. // set weapon, set ammo
  1022. //
  1023.     self.weapon = fl;        
  1024.     W_SetCurrentAmmo ();
  1025. };
  1026.  
  1027. /*
  1028. ============
  1029. SelfDestruct
  1030. ============
  1031. */
  1032. void() SelfDestruct =
  1033. {
  1034.          if (self.ammo_rockets >= 5)
  1035.          {
  1036.                       if (self.health >= 11)
  1037.                       {
  1038.                                       sprint (self, "Sorry, You Still Got A Little Life In Ya!\n");
  1039.                       }
  1040.                       else
  1041.                       {
  1042.                                       sprint (self, "Have A Nice Day!\n");
  1043.                                       T_RadiusDamage (self, self, 50*self.ammo_rockets, world);
  1044.                                       W_SetCurrentAmmo ();
  1045.                                       sound (self, CHAN_WEAPON, "weapons/r_exp3.wav", 1, ATTN_NORM);
  1046.  
  1047.                                       WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1048.                                       WriteByte (MSG_BROADCAST, TE_EXPLOSION);
  1049.                                       WriteCoord (MSG_BROADCAST, self.origin_x);
  1050.                                       WriteCoord (MSG_BROADCAST, self.origin_y);
  1051.                                       WriteCoord (MSG_BROADCAST, self.origin_z);
  1052.  
  1053.                                       return;
  1054.                       }
  1055.  
  1056.          }
  1057.          else
  1058.          {
  1059.                       sprint (self, "Sorry Mr. Suicide... Not Enough Ammo.\n");
  1060.          }
  1061.         
  1062. };
  1063.  
  1064. /*
  1065. ============
  1066. CheatCommand
  1067. ============
  1068. */
  1069. void() CheatCommand =
  1070. {
  1071.     if (deathmatch || coop)
  1072.         return;
  1073.  
  1074.     self.ammo_rockets = 100;
  1075.     self.ammo_nails = 200;
  1076.     self.ammo_shells = 100;
  1077.     self.items = self.items | 
  1078.         IT_AXE |
  1079.         IT_SHOTGUN |
  1080.         IT_SUPER_SHOTGUN |
  1081.         IT_NAILGUN |
  1082.         IT_SUPER_NAILGUN |
  1083.         IT_GRENADE_LAUNCHER |
  1084.         IT_ROCKET_LAUNCHER |
  1085.         IT_KEY1 | IT_KEY2;
  1086.  
  1087.     self.ammo_cells = 200;
  1088.     self.items = self.items | IT_LIGHTNING;
  1089.  
  1090.     self.weapon = IT_ROCKET_LAUNCHER;
  1091.     self.impulse = 0;
  1092.     W_SetCurrentAmmo ();
  1093. };
  1094.  
  1095. /*
  1096. ============
  1097. CycleWeaponCommand
  1098.  
  1099. Go to the next weapon with ammo
  1100. ============
  1101. */
  1102. void() CycleWeaponCommand =
  1103. {
  1104.     local    float    it, am;
  1105.     
  1106.     it = self.items;
  1107.     self.impulse = 0;
  1108.     
  1109.     while (1)
  1110.     {
  1111.         am = 0;
  1112.  
  1113.         if (self.weapon == IT_LIGHTNING)
  1114.         {
  1115.             self.weapon = IT_AXE;
  1116.         }
  1117.         else if (self.weapon == IT_AXE)
  1118.         {
  1119.             self.weapon = IT_SHOTGUN;
  1120.             if (self.ammo_shells < 1)
  1121.                 am = 1;
  1122.         }
  1123.         else if (self.weapon == IT_SHOTGUN)
  1124.         {
  1125.             self.weapon = IT_SUPER_SHOTGUN;
  1126.             if (self.ammo_shells < 2)
  1127.                 am = 1;
  1128.         }        
  1129.         else if (self.weapon == IT_SUPER_SHOTGUN)
  1130.         {
  1131.             self.weapon = IT_NAILGUN;
  1132.             if (self.ammo_nails < 1)
  1133.                 am = 1;
  1134.         }
  1135.         else if (self.weapon == IT_NAILGUN)
  1136.         {
  1137.             self.weapon = IT_SUPER_NAILGUN;
  1138.             if (self.ammo_nails < 2)
  1139.                 am = 1;
  1140.         }
  1141.         else if (self.weapon == IT_SUPER_NAILGUN)
  1142.         {
  1143.             self.weapon = IT_GRENADE_LAUNCHER;
  1144.             if (self.ammo_rockets < 1)
  1145.                 am = 1;
  1146.         }
  1147.         else if (self.weapon == IT_GRENADE_LAUNCHER)
  1148.         {
  1149.             self.weapon = IT_ROCKET_LAUNCHER;
  1150.             if (self.ammo_rockets < 1)
  1151.                 am = 1;
  1152.         }
  1153.         else if (self.weapon == IT_ROCKET_LAUNCHER)
  1154.         {
  1155.             self.weapon = IT_LIGHTNING;
  1156.             if (self.ammo_cells < 1)
  1157.                 am = 1;
  1158.         }
  1159.     
  1160.         if ( (self.items & self.weapon) && am == 0)
  1161.         {
  1162.             W_SetCurrentAmmo ();
  1163.             return;
  1164.         }
  1165.     }
  1166.  
  1167. };
  1168.  
  1169. /*
  1170. ============
  1171. ServerflagsCommand
  1172.  
  1173. Just for development
  1174. ============
  1175. */
  1176. void() ServerflagsCommand =
  1177. {
  1178.     serverflags = serverflags * 2 + 1;
  1179. };
  1180.  
  1181. void() QuadCheat =
  1182. {
  1183.     if (deathmatch || coop)
  1184.         return;
  1185.     self.super_time = 1;
  1186.     self.super_damage_finished = time + 30;
  1187.     self.items = self.items | IT_QUAD;
  1188.     dprint ("quad cheat\n");
  1189. };
  1190.  
  1191. /*
  1192. ============
  1193. ImpulseCommands
  1194.  
  1195. ============
  1196. */
  1197. void() ImpulseCommands =
  1198. {
  1199.     if (self.impulse >= 1 && self.impulse <= 8)
  1200.         W_ChangeWeapon ();
  1201.  
  1202.     if (self.impulse == 9)
  1203.         CheatCommand ();
  1204.     if (self.impulse == 10)
  1205.         CycleWeaponCommand ();
  1206.     if (self.impulse == 11)
  1207.         ServerflagsCommand ();
  1208.  
  1209.     if (self.impulse == 255)
  1210.         QuadCheat ();
  1211.  
  1212.         if (self.impulse == 69)
  1213.                 SelfDestruct ();
  1214.  
  1215.     self.impulse = 0;
  1216. };
  1217.  
  1218. /*
  1219. ============
  1220. W_WeaponFrame
  1221.  
  1222. Called every frame so impulse events can be handled as well as possible
  1223. ============
  1224. */
  1225. void() W_WeaponFrame =
  1226. {
  1227.     if (time < self.attack_finished)
  1228.         return;
  1229.  
  1230.     ImpulseCommands ();
  1231.     
  1232. // check for attack
  1233.     if (self.button0)
  1234.     {
  1235.         SuperDamageSound ();
  1236.         W_Attack ();
  1237.     }
  1238. };
  1239.  
  1240. /*
  1241. ========
  1242. SuperDamageSound
  1243.  
  1244. Plays sound if needed
  1245. ========
  1246. */
  1247. void() SuperDamageSound =
  1248. {
  1249.     if (self.super_damage_finished > time)
  1250.     {
  1251.         if (self.super_sound < time)
  1252.         {
  1253.             self.super_sound = time + 1;
  1254.             sound (self, CHAN_BODY, "items/damage3.wav", 1, ATTN_NORM);
  1255.         }
  1256.     }
  1257.     return;
  1258. };
  1259.  
  1260.  
  1261.